__metaclass__ = type

from checkers import utils

class Game:
    """A game is similar to a problem, but it has a utility for each
    state and a terminal test instead of a path cost and a goal
    test. To create a game, subclass this class and implement
    legal_moves, make_move, utility, and terminal_test. You may
    override display and successors or you can inherit their default
    methods. You will also need to set the .initial attribute to the
    initial state; this can be done in the constructor.
    """

    def legal_moves(self, state):
        """Return a list of the allowable moves at this point.
        """
        utils.abstract()

    def make_move(self, move, state):
        """Return the state that results from making a move from a state.
        """
        utils.abstract()

    def utility(self, state, player):
        """Return the value of this final state to player.
        """
        utils.abstract()

    def terminal_test(self, state):
        """Return True if this is a final state for the game.
        """
        return not self.legal_moves(state)

    def to_move(self, state):
        """Return the player whose move it is in this state.
        """
        return state.to_move

    def display(self, state):
        """Print or otherwise display the state.
        """
        print state

    def successors(self, state):
        """Return a list of legal (move, state) pairs.
        """
        return [(move, self.make_move(move, state))
                for move in self.legal_moves(state)]

    def __repr__(self):
        return '<%s>' % self.__class__.__name__
